iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 8
0

This is the FINAL lesson of Machine Learning APIs!!!

Time flies!!! /images/emoticon/emoticon08.gif

This lesson is quite interesting.

We add in Kubernetes to make this course more practical.

Don't worry! We are going to guide you steps by steps.


The Awwvision lab uses Kubernetes and Cloud Vision API to demonstrate how to use the Vision API to classify (label) images from Reddit's /r/aww subreddit and display the labelled results in a web app.

Awwvision has three components:

  1. A simple Redis instance.
  2. A web app that displays the labels and associated images.
  3. A worker that handles scraping Reddit for images and classifying them using the Vision API. Cloud Pub/Sub is used to coordinate tasks between multiple worker instances.

  1. Open Google Cloud Platform ( follow the step in A Tour of Qwiklabs and Google Cloud )

  2. Activate Cloud Shell
    Like what we did in the previous lesson.

  3. Create a Kubernetes Engine cluster
    We will use gcloud, Google Cloud's command-line tool, to set up a Kubernetes Engine cluster. The cloud platform scope is used to allow access to the Pub/Sub and Vision APIs.

Create a cluster in the us-central1-a zone:

gcloud config set compute/zone us-central1-a

Start up the cluster:

gcloud container clusters create awwvision \
    --num-nodes 2 \
    --scopes cloud-platform

Use the container's credentials:

gcloud container clusters get-credentials awwvision

Verify that everything is working using the kubectl command-line tool:

kubectl cluster-info
  1. Create a virtual environment

Download and update the packages list:

sudo apt-get update

Python virtual environments are used to isolate package installation from the system:

sudo apt-get install virtualenv

Do you want to continue? [Y/n]: Y

virtualenv -p python3 venv

Activate the virtual environment:

source venv/bin/activate
  1. Get the Sample

Add sample data to our project:

git clone https://github.com/GoogleCloudPlatform/cloud-vision
  1. Deploy the sample

Change to the python/awwvision directory in the cloned cloud-vision repo:

cd cloud-vision/python/awwvision

Once in the awwvision directory, run make all to build and deploy everything:

make all

As part of the process, Docker images will be built and uploaded to the Google Container Registry private container registry. In addition, yaml files will be generated from templates, filled in with information specific to your project, and used to deploy the redis, webapp, and worker Kubernetes resources for the lab.

  1. Check the Kubernetes resources on the cluster

List the pods:

kubectl get pods

Make sure all of your pods have a Running before executing the next command:
https://ithelp.ithome.com.tw/upload/images/20200921/20130054bgyMPww6j7.png

List the deployments:

kubectl get deployments -o wide

You can see the number of replicas specified for each, and the images used:
https://ithelp.ithome.com.tw/upload/images/20200921/201300541PyHTmHhM4.png

Once deployed, get the external IP address of the webapp service by running:

kubectl get svc awwvision-webapp

Assigned external IP to be listed:
https://ithelp.ithome.com.tw/upload/images/20200921/201300543mipj0sGiB.png

  1. Visit your new web app and start its crawler

Copy and paste the external IP of the awwvision-webapp service from the above result into a new browser to open the webapp, then click Start the Crawler button.

https://ithelp.ithome.com.tw/upload/images/20200921/20130054HuEM3eRiI3.png

You will see images from the /r/aww subreddit classified by the labels provided by the Vision API.
https://ithelp.ithome.com.tw/upload/images/20200921/201300540MHoYWhVHK.png

If you see some of the images classified multiple times, it's because multiple labels are detected for them.


HOORAY!!!!! We finish Machine Learning APIs course!!!!!

Such a great accomplishment right!!! /images/emoticon/emoticon42.gif

It's quite tedious at first, but once you started doing with others together, the path no longer gave you harshness.

Hope you enjoy today's sharing ~


上一篇
Entity and Sentiment Analysis with the Natural Language API
下一篇
Let's summarize ...
系列文
Machine Learning Study Jam 202012
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言